// 传统监听页面滚动
import { onMounted, onUnmounted, ref } from "vue";

export default function useScrollTop() {
  let ScrollTop = ref(0);

  const handleGetScrollTop = () => {
    ScrollTop.value = document.documentElement.scrollTop;
    // console.log(ScrollTop.value);
  };

  // 组件挂载时
  onMounted(() => {
    window.addEventListener("scroll", handleGetScrollTop);
  });

  // 组件卸载时
  onUnmounted(() => {
    window.removeEventListener("scroll", handleGetScrollTop);
  });

  return ScrollTop;
}
